#if !defined(AFX_HISTORICALDATASURFACE_H__C7B06FE7_3AAF_4040_B3CE_8E3971B27A09__INCLUDED_)
#define AFX_HISTORICALDATASURFACE_H__C7B06FE7_3AAF_4040_B3CE_8E3971B27A09__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// HistoricalDataSurface.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CHistoricalDataSurface window

#include "BaseSurface.h"
#include "CurveWnd.h"
#include "BaseMethodCallback.h"

#include "GUIBaseLib\ToolTipBitmapButton.h"

#define WM_APP_CURVEGENERATED (WM_APP+110)

#define CURVE_NOTGENERATE   0
#define CURVE_GENERATING    1
#define CURVE_TIMEOUT       2
#define CURVE_CANCELBYUSER  3
#define CURVE_GENERATED     4

struct RecordItem;
struct ReportItem;
class BaseMethodPerformer;

class CHistoricalDataSurface : public CBaseSurface, public BaseMethodCallback
{
// Construction
public:
	CHistoricalDataSurface(CBasePanel * pPanel);

// Attributes
protected:
  static int m_nGDIResCounter;
  static CFont * m_pFont;

  CListCtrl m_listctrl;
  CDateTimeCtrl m_dtBeginDate;
  CDateTimeCtrl m_dtBeginTime;
  CDateTimeCtrl m_dtEndDate;
  CDateTimeCtrl m_dtEndTime;
  CToolTipBitmapButton m_btnGenCurve;
  CToolTipBitmapButton m_btnMenuGenCurve;
  CToolTipBitmapButton m_btnCancelCurve;
  CComboBox m_cbPenWidth;
  CComboBox m_cbHorzZoomScale;
  CComboBox m_cbVertZoomScale;
  CComboBox m_cbLinkingStyle;
  CCurveWnd m_wndCurve;
  CTime m_timeBegin;
  CTime m_timeEnd;
  int m_nPenWidth;
  int m_nHorzZoomScale;
  int m_nVertZoomScale;
  int m_nLinkingStyle;
  bool m_bShowListCtrl;
  RecordAckStruct * m_pRecordAckStruct;
  BaseMethodPerformer * m_pRecordQueryPerformer;
  int m_nCurveStatus;
  ReportItem * m_pReportItem;

public:
  CMutex m_mutexCurveData;

// Operations
public:
  virtual bool Create(CWnd * pParentWnd);
  virtual void Paint(CDC& dc);
  virtual void UpdateDefinitionDisplay(BaseCoalMineUnit * pCoalMineUnit);
  virtual void UpdateDataDisplay(BaseCoalMineUnit * pCoalMineUnit, BaseMonitoringUnit * pMonitoringUnit);
  virtual void ApplyOptions(DWORD dwOptionPagesMask);
  virtual bool CanBeActivated() const;

  virtual void Callback(BaseMethodPerformer * pPerformer);

  void GetCurveParam(CurveParamStruct * pCurveParamStruct) const;
  RecordAckStruct * GetCurveData();
  void SetCurveData(RecordAckStruct * pRecordAckStruct);
  CTimeSpan GetHourSpan(const CTime& timeBegin, const CTime& timeEnd) const;
  void InsertRecordsToListCtrl();
  void InsertRecordToListCtrl(CListCtrl& listctrl, RecordItem * pRecord, BaseMonitoringUnit * pMonitoringUnit) const;
  CFont * GetpFont() const {return m_pFont;}
  int GetCurveStatus() const {return m_nCurveStatus;}
  bool BuildReportItem();
  void DrawCurve(CDC& dc, const CRect& rect);

protected:
  void CreateGDIResource();
  void DestroyGDIResource();
  bool IsPointOnEjectionLabel(const CPoint& point) const;
  void GetEjectionLabelRect(LPRECT lpRect) const;
  UINT GetEjectionLabelId() const;
  void GetListCtrlRect(LPRECT lpRect) const;
  void GetCurveWndRect(LPRECT lpRect) const;
  void GetCurveWndClientRect(LPRECT lpRect) const;
  void GetTimeAxisRect(LPRECT lpRect) const;
  void GetDataAxisRect(LPRECT lpRect) const;
  void DrawTimeAxis(CDC& dc, const CRect& rect);
  void DrawDataAxis(CDC& dc, const CRect& rect);
  void RedrawTimeAxis();
  void RedrawDataAxis();
  void GenerateCurve();

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CHistoricalDataSurface)
	//}}AFX_VIRTUAL

// Implementation
public:

	virtual ~CHistoricalDataSurface();

	// Generated message map functions
protected:
	//{{AFX_MSG(CHistoricalDataSurface)
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnViewCurveInfo();
	afx_msg void OnViewExcessStatistics();
	afx_msg void OnViewDayStatistics();
	afx_msg void OnPrintCurve();
	afx_msg void OnGenerateDefaultCurve();
	afx_msg void OnGenerate8HoursCurve();
	afx_msg void OnGenerateTodayCurve();
	afx_msg void OnGenerateYesterdayCurve();
	afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
	afx_msg void OnExportRecords();
	//}}AFX_MSG
  afx_msg void OnGenerateCurve();
  afx_msg void OnMenuGenerateCurve();
  afx_msg void OnCancelCurve();
  afx_msg void OnPenWidthChanged();
  afx_msg void OnHorzZoomScaleChanged();
  afx_msg void OnVertZoomScaleChanged();
  afx_msg void OnLinkingStyleChanged();
  afx_msg LRESULT OnCurveWndHScroll(WPARAM wParam, LPARAM lParam);
  afx_msg LRESULT OnCurveWndVScroll(WPARAM wParam, LPARAM lParam);
  afx_msg LRESULT OnCurveGenerated(WPARAM wParam, LPARAM lParam);
	DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_HISTORICALDATASURFACE_H__C7B06FE7_3AAF_4040_B3CE_8E3971B27A09__INCLUDED_)
